package com.vlong.town.controller.server.comm;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.github.pagehelper.PageHelper;
import com.vlong.town.controller.base.BaseController;
import com.vlong.town.entity.comm.CommInfo;
import com.vlong.town.service.comm.CommInfoService;
/**
 * 信息互联Rest接口Controller
 * @author Assassin
 */
@RequestMapping("/rest/comm")
@RestController
public class CommInfoRestController extends BaseController{

	   @Autowired
	   private CommInfoService commInfoService;// 信息互联信息业务实现类
	   
	   /**
	     * 查询信息互联
	     * @param pageNo 当前页码
	     * @param pageSize 每页显示记录数
	     * @return List<CommInfo>
	     */
	    @GetMapping("/list/{pageNo}/{pageSize}")
	    public List<CommInfo> list(
	            @PathVariable(required=true, value="pageNo") Integer pageNo,
	            @PathVariable(required=true, value="pageSize") Integer pageSize) {
	        PageHelper.startPage(getPageNo(pageNo), getPageSize(pageSize));
	        PageHelper.orderBy("update_time DESC");
	        List<CommInfo> commInfoList = this.commInfoService.queryList(null, null, null);
	        return commInfoList;
	    }
	    
	    
	    /**
	     * 小程序
	     * 查询信息互联
	     * @param pageNo 当前页码
	     * @param pageSize 每页显示记录数
	     * @return List<CommInfo>
	     */
	    @GetMapping("/listXcx")
	    public List<CommInfo> listXcx(){
	        List<CommInfo> commInfoList = this.commInfoService.queryList(null, null, null);
	        for (CommInfo commInfo : commInfoList) {
	        	Long createTime = commInfo.getCreateTime();
	        	SimpleDateFormat  sdf=new  SimpleDateFormat("yyyy-MM-dd");
	        	Date date = new  Date(createTime);
	        	String format = sdf.format(date);
	        	commInfo.setCreateDate(format);
			}
	        return commInfoList;
	    }
	    
	    /**
	     * 查询信息互联详情
	     * @param id 信息互联id
	     * @return CommInfo
	     */
	    @GetMapping("/detail/{id}")
	    public CommInfo detail(@PathVariable(required=true, value="id") Long id) {
	    	return commInfoService.queryById(id);
	    }
}
